package com.v1.video.activity;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;

import com.umeng.analytics.MobclickAgent;
import com.v1.video.Constant;
import com.v1.video.R;
import com.v1.video.fragment.GuideFragment;
import com.v1.video.util.Helper;
import com.v1.video.util.Logger;

public class GuideActivity extends BaseActivity {
    private static final int GUIDE_PAGE_NUM = 2;
    private ViewPager mViewPager;
    private SectionsPagerAdapter mSectionsPagerAdapter;
    private List<Fragment> fragments;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        MobclickAgent.onEvent(this, "introduce_id");
        setContentView(R.layout.activity_guide);
    }
    
    @Override
    protected void initView() {
        mViewPager = (ViewPager) findViewById(R.id.vp_guide);
    }

    @Override
    protected void initData() {
        fragments = new ArrayList<Fragment>();
        for(int i = 0;i<GUIDE_PAGE_NUM;i++){
             fragments.add(GuideFragment.newInstance(i));
        }
        mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
        
        mViewPager.setAdapter(mSectionsPagerAdapter);
    }

    @Override
    protected void setListener() {
    	
    }

    private class SectionsPagerAdapter extends FragmentPagerAdapter {

        public SectionsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }

        @Override
        public int getCount() {
            return fragments.size();
        }

        
    }
    
    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("启动介绍页");
        MobclickAgent.onResume(this);
    }
    
    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("启动介绍页");
        MobclickAgent.onPause(this);
    }
    
//    private void goToHomePage(Context context) {
//		SharedPreferences sp = context.getSharedPreferences(Constant.APP_INFO,
//				context.MODE_PRIVATE);
//		Editor editor = sp.edit();
//		editor.putBoolean("first_start", false);
//		editor.commit();
//		// startActivity(new Intent(context,HomepageActivity.class));
//		startActivity(new Intent(context, MainPageNewActivity.class));
//		GuideActivity.this.finish();
//	}
}
